
import 'package:flutter/material.dart';
import 'package:flutter_ahj_app/base/values/dimens.dart';


typedef GestureTapCallback = void Function();
class JTextField extends StatefulWidget {

//  final String labelText;
  final String errorText;
  final TextInputType keyboardType;///键盘类型
  final TextEditingController textEditingController;///获取值
  final bool obscureText;///是否隐藏 适用于 输入密码
  final FocusNode focusNode;///焦点
  final ValueChanged<String> onChanged;///
  final TextStyle style;
  final TextStyle labelStyle;
  final TextStyle hintStyle;
  final Color cursorColor;///光标颜色
  final bool readOnly;
  final InputBorder enabledBorder;///默认 时的 边框
  final InputBorder focusedBorder;///选中时的 边框
  final bool enabled;///是否禁用
  final Widget icon;///左边图票 👈
  final Widget suffixIcon;///右边图标 👉
  final GestureTapCallback onTap;

  InputBorder _borderStyle;
  String  _hintText, _labelText;
  ///
  JTextField({
    Key key,
//    this.labelText,
    this.keyboardType,
    this.textEditingController,
    this.errorText,
    this.focusNode,
    this.onChanged,
    this.obscureText = false,
    this.style,
    this.labelStyle,
    this.hintStyle,
    this.cursorColor,
    this.enabledBorder,
    this.focusedBorder,
    this.readOnly = false,
    this.enabled,
    this.icon,
    this.suffixIcon,
    this.onTap,
    String hintText,
  }) : super(key: key)

  {
    _borderStyle = UnderlineInputBorder();
    _hintText = hintText;
  }



  JTextField.outlineInputBorder({
    this.keyboardType,
    this.textEditingController,
    this.errorText,
    this.focusNode,
    this.onChanged,
    this.obscureText = false,
    this.style,
    this.labelStyle,
    this.hintStyle,
    this.cursorColor,
    this.enabledBorder,
    this.focusedBorder,
    this.readOnly = false,
    this.enabled,
    this.icon,
    this.suffixIcon,
    this.onTap,
    String labelText,
  }){
    _borderStyle = OutlineInputBorder();
    _labelText = labelText;
  }

  @override
  _InputViewState createState() => _InputViewState();

}
class _InputViewState extends State<JTextField> {
  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.fromLTRB(15, 15, 15, 0),
      child: TextField(
        onTap: widget.onTap,
        enabled: widget.enabled,
        obscureText: widget.obscureText,
        controller: widget.textEditingController,
        keyboardType: widget.keyboardType,
        focusNode: widget.focusNode,
        readOnly: widget.readOnly,
        decoration: InputDecoration(
          icon: widget.icon,
          suffixIcon: widget.suffixIcon,
          hintText: widget._hintText,
          border: widget._borderStyle,
          labelText: widget._labelText,
          contentPadding: EdgeInsets.all(Dimens.dimens16),
          labelStyle: widget.labelStyle,
          hintStyle: widget.hintStyle,
          enabledBorder: widget.enabledBorder,
          focusedBorder: widget.focusedBorder,
          errorText:  widget.errorText,
        ),
        style: widget.style,
        cursorColor: widget.cursorColor,
        onChanged: widget.onChanged,
      ),
    );
  }
}
